package org.kernely.ui.login;

import org.kernely.ui.mvp.IKernelyView;

import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.Reindeer;

public class KernelyLoginView extends VerticalLayout implements IKernelyView{
	
	
	/**
	 * The serial Version ID
	 */
	private static final long serialVersionUID = -3787976801554331145L;
	
	private TextField login;
	private TextField password;
	private Button loginButton;
	private Button clearButton;
	private Button validateButton;
	private Form form;

	/**
	 * KernelyLoginView's constructor
	 */
	public KernelyLoginView(){
		login = new TextField("Username");
		login.setWidth("100%");

		password = new TextField("Password");
		password.setSecret(true);
		password.setWidth("100%");

		HorizontalLayout buttons = new HorizontalLayout();
		buttons.setSpacing(true);

		loginButton = new Button("Login");
		buttons.addComponent(loginButton);
		clearButton = new Button("Clear");
		buttons.addComponent(clearButton);
		buttons.setComponentAlignment(loginButton, Alignment.MIDDLE_CENTER); // Obviously, it's a fail: buttons are not centered...
		buttons.setComponentAlignment(clearButton, Alignment.MIDDLE_CENTER);

		form = new Form();
		form.setDescription("Welcome on Kernely, please login");
		form.addField("login", login);
		form.addField("password", password);
		
		form.getFooter().addComponent(buttons);
		form.setWidth(200, UNITS_PIXELS);
		this.setStyleName(Reindeer.LAYOUT_BLACK);
		this.setWidth(200, UNITS_PIXELS);
		this.addComponent(form);
		this.setHeight(100, Sizeable.UNITS_PERCENTAGE);

		this.setSizeFull();
		this.addComponent(form);
		this.setComponentAlignment(form, Alignment.MIDDLE_CENTER);

		login.focus();
		
	}
	
	
	
	/**
	 * @see org.kernely.core.service.IKernelyView#getComponent()
	 */
	@Override
	public final Component getComponent() {
		return this;
	}



	/**
	 * Gets the login
	 * @return the login
	 */
	public final TextField getLogin() {
		return login;
	}



	/**
	 * Gets the password
	 * @return the password
	 */
	public final TextField getPassword() {
		return password;
	}



	/**
	 * Gets the loginButton
	 * @return the loginButton
	 */
	public final Button getLoginButton() {
		return loginButton;
	}



	/**
	 * Gets the clearButton
	 * @return the clearButton
	 */
	public final Button getClearButton() {
		return clearButton;
	}



	/**
	 * Gets the validateButton
	 * @return the validateButton
	 */
	public final Button getValidateButton() {
		return validateButton;
	}



	/**
	 * Gets the login form
	 * @return the login form
	 */
	public final Form getForm() {
		return form;
	}
	
	

}
